package com.godz.frontData.index3;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;

@RestController
public class uploadIndex3 {
    //主页3存放地址是assets/myIndex3/img
    @PostMapping("/index3/post/uploadImg")
    public String uploadImg(@RequestPart("file") MultipartFile file){
        if (!file.isEmpty()) {
            String property = System.getProperty("user.dir");//得到当前路径
            String filename = file.getOriginalFilename();
            try {
                file.transferTo(new File(property + "\\src\\main\\resources\\static\\assets\\myIndex3\\img\\" + filename));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "上传成功";
    }
}
